package cn.rkylin.oms.system.unit.handler;

import org.springframework.stereotype.Component;

import cn.rkylin.oms.common.event.EventHandler;
import cn.rkylin.oms.common.utils.RedisUtils;
import cn.rkylin.oms.system.unit.event.AfterRBACChangedEvent;

/**
 * 组织、角色、权限、人员变更事件处理器
 * 
 * @author wangxiaoyi
 * @since 2018-1-29 13:52:57
 */
@Component
public class AfterRBACChangedEventHandler extends EventHandler<AfterRBACChangedEvent> {

	@Override
	public void onEvent(AfterRBACChangedEvent event) throws Exception {
	    // 删菜单缓存，userMenus:id
		if (event.getAffectUserIds() != null) {
		    for (String affectUserId : event.getAffectUserIds()) {
		        // 去缓存删除此人
		        RedisUtils.del("userMenus:" + affectUserId);
		        System.out.println(">>>>>>> del userMenu cache:" + "userMenus:" + affectUserId);
		    }
		}

        // 删当前用户缓存，user:account
        if (event.getAffectUserAccounts() != null) {
            for (String affectUserAccount : event.getAffectUserAccounts()) {
                // 去缓存删除此人
                RedisUtils.del("user:" + affectUserAccount);
                System.out.println(">>>>>>> del user cache:" + "user:" + affectUserAccount);
            }
        }
	}

}
